/************************************************************
 * @file: nvsns_init.h
 * @author: Hao
 * @version: V0.0
 * @data: 2023/07/28
 * @brief: nvsns module initilization file
 * @note:
 * @Copyright (C) 2023 Novosense All rights reserved.
 ************************************************************/

/************************************************************
 ************************************************************
 * @par Edition History
 * -V0.0  2023.07.28
 *        - Initilization file
 *
 ************************************************************/

#ifndef __PERIPHERAL_CONFIG_H__
#define __PERIPHERAL_CONFIG_H__

/******************** System information ************************/
/** System clock **/
#define SYS_CLK                 (32000000)

/******************** EPWM config definition ********************/

/** EPWM input clock fpwm=fsys/2^N*/
#define EPWM_FSEL               (0)

/** EPWM period compare setting. */
#define EPWM_PERIOD             (800)     //period = fepwm / (MOT_EPWM_PERIOD_COMPARE * 2) // fepwm = 32MHz

/** EPWM frequency(HZ). 32Mhz/(2*800). 20kHZ*/
#define EPWM_FREQUENCY_HZ       (SYS_CLK / (2 * EPWM_PERIOD))

/** EPWM alignment mode.0: center 1: edge */
#define EPWM_PAM                (0)

/** EPWM switch on slew rate
 * 0: normal 1:reserved 2:fast 3: very fast
 */
#define EPWM_FSON               (3)

/** EPWM switch off slew rate
 * 0:normal 1:reserved 2:fast 3: very fast
 */
#define EPWM_FSOFF              (3)

/** EPWM over-current filter time(on 32Mhz).
 * 0:2.4-2.8us 1:4.8-5.6us
 * 2:9.6-11.2us 3:19.2-22.4us
 */
#define EPWM_OCFT               (0)


/******************** CAPCOM config definition ********************/
/* CAPCOM clock prescaler */
#define CAPCOM_CLK_PS           (159)

/* CAPCOM frequency */
#define CAPCOM_CLK_HZ           (SYS_CLK / (CAPCOM_CLK_PS + 1))

#define CAPCOM_FILTER_TIME      (0)

#define CAPCOM0_PREEMPT_PRIO    (1) // the last preemption priority

#define CAPCOM0_IRQ_PRIO        (0) // priority of ADC interrupt

#define CAPCOM1_PREEMPT_PRIO    (1) // the last preemption priority

#define CAPCOM1_IRQ_PRIO        (0) // priority of ADC interrupt

#define CAPCOM2_PREEMPT_PRIO    (1) // the last preemption priority

#define CAPCOM2_IRQ_PRIO        (0) // priority of ADC interrupt

/******************** BEMFC config definition ********************/
/* BEMFC blanking time
	Setting | time [us]
	--------|----------
	0		| 0
	1		| 1.4 to 1.6
	2		| 3.0 to 3.2
	3		| 4.6 to 4.8
	4		| 6.2 to 6.4
	5		| 7.8 to 8.0
	6		| 9.4 to 9.6
	...	| ...
	14 	| 22.2 to 22.4
	15	| 23.8 to 24.0
*/
#define BEMFC_BLANKING_TIME     (2)

/* BEMFC deglitch time
 Setting  | time [us]
 -------- | -------------
 0  			| 0 (bypassed)
 1  			| 0.6 to 0.8
 2  			| 1.0 to 1.2
 3  			| 3.0 to 3.2
*/
#define BEMFC_DEGLITCH_FILTER_TIME  (3)

/******************** ADC config definition ********************/

#define ADC_PREEMPT_PRIO       (0) // the last preemption priority

#define ADC_IRQ_PRIO           (0) // priority of ADC interrupt

/******************** TMR1 config definition ********************/

#define TMR1_PREEMPT_PRIO      (1) // the last preemption priority

#define TMR1_IRQ_PRIO          (3) // priority of ADC interrupt

/******************** Fault detection config definition ********************/
#define ECU_BUS_HOV_ENABLE     (0) // hardware over voltage detection interrupt. 0:disable 1:enable

#define ECU_BUS_HOV_FT         (15) // BVDD hardware over voltage deglitch time. N*0.5us

#define ECU_BUS_HOV_BRAKE      (0) // bridge brake when BVDD over voltage. 0:disable 1:enable

#define ECU_BUS_HUV_ENABLE     (0) // hardware under voltage detection interrupt. 0:disable 1:enable

#define ECU_BUS_HUV_LEVEL      (1) // hardware under voltage trig level: 0: 6.5V 1:7.5V 2:8.5V 3:9.5V

#define ECU_BUS_HUV_FT         (4) // BVDD hardware under voltage deglitch time. N*0.5us

#define ECU_BUS_HUV_BRAKE      (0) // bridge brake when BVDD under voltage. 1:enable 0:disable

#define ECU_BUS_OT_ENABLE      (0) // over temperature detection interrupt. 0:disable 1:enable

#define ECU_BUS_OT_FT          (4) // over temperature deglitch time. N*0.5us

#define ECU_BUS_OT_BRAKE       (0) // bridge brake when over temperature. 0:disable 1:enable

#define ECU_MOT_CP_OV_EANABLE  (0) // chargepump over voltage interrupt. 0:disable 1:enable

#define ECU_MOT_CP_OV_FT       (1) // chargepump OV filter: -1:disable 0:1us 1:2us 2:4us 3:8us

#define ECU_MOT_CP_CAE         (0) // chargepump auto close when cp OV. 0:disable 1:enable

#define ECU_FAULT_PREEMPT_PRIO (1) // fault detection preemption priority

#define ECU_FAULT_IRQ_PRIO     (1) // fault detection priority

#endif

